﻿using System;
using System.Collections.Generic;
using ATTools.Models;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Settings;
using Orchard.UI.Admin.Notification;
using Orchard.UI.Notify;

namespace ATTools
{
    public class ATToolsNotification : INotificationProvider
    {
        private readonly ISiteService _siteService;
        public Localizer T { get; set; }

        public ATToolsNotification(ISiteService siteService)
        {
            _siteService = siteService;

            T = NullLocalizer.Instance;
        }



        #region INotificationProvider Members

        public IEnumerable<NotifyEntry> GetNotifications()
        {
            bool notify = false;
            try
            {
                var toolsSettings = _siteService.GetSiteSettings().As<ATToolsSettingsPart>();
                notify = string.IsNullOrWhiteSpace(toolsSettings.Record.BingAppID);
            }
            catch (Exception) //Ignore Exception, caused when ATToolsSettingsPart need to be updated.
            { }

            if (notify)
                yield return new NotifyEntry { Message = T("Please remember to enter a Bing App ID under Settings"), Type = NotifyType.Information };
        }

        #endregion
    }
}